// pages/shop_panel/index.js
import {navTo,navToTab,onInput,onClick,showText} from '../../utils/reuse'
import{getXstop,addAdmin,getShopVip,addVip,getCourseDetailQr} from '../../api/index'
import {baseURL} from '../../utils/request'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    status:1,
    userInfo:{},
    is_admin:[],
    subobj:{
      maxAdmin:false,
      minAdmin:false,
      coach:false
    },
    class:{}
  },
  Vipsubmit(e){
    var obj ={
      uid:wx.getStorageSync('uid'),
      shop_id:wx.getStorageSync('shop_id'),
      xuid:this.data.userInfo.id,
      // endtime:
    }
    addVip(obj).then(res=>{
      if(res.sta == 1){
        showText(res.msg,1)
        setTimeout(() => {
          wx.navigateBack()
        }, 1000);
      }else{
        showText(res.msg,2)
      }
    })
  },

  submit(e){
    var obj = {
      uid:wx.getStorageSync('uid'),
      shop_id:wx.getStorageSync('shop_id'),
      xuid:this.data.userInfo.id,
      is_admin:e.currentTarget.dataset.key
    }
    addAdmin(obj).then(res=>{
      if(res.sta == 1){
        showText(res.msg,1)
        wx.navigateBack()
      }else{
        showText(res.msg,2)
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // 1添加人员 2添加会员 3教练加课时
    this.setData({
      status:options.id
    })
    var userId = wx.getStorageSync('userId')
    if(userId){
      if(options.id == 1){
        var obj = {
          uid:wx.getStorageSync('uid'),
          xuid:userId,
          shop_id:wx.getStorageSync('shop_id')
        }
        getXstop(obj).then(res=>{
          if(res.sta == 1){
            console.log(res.isadmin)
            if(res.isadmin.length >= 1){
              res.isadmin.find(item=>item == 1) ? this.setData({'subobj.maxAdmin':true}) : ''
              res.isadmin.find(item=>item == 2) ? this.setData({'subobj.minAdmin':true}) : ''
              res.isadmin.find(item=>item == 3) ? this.setData({'subobj.coach':true}) : ''
            }
            this.setData({
              userInfo:res.msg,
              is_admin:res.isadmin
            })
          }
        })
        wx.removeStorageSync('userId')
      }else if(options.id == 2){
        var obj = {
          uid:wx.getStorageSync('uid'),
          xuid:userId,
          shop_id:wx.getStorageSync('shop_id')
        }
        getShopVip(obj).then(res=>{
          if(res.sta == 1){
            this.setData({
              userInfo:res.msg,
              is_admin:res.isadmin
            })
          }
        })
        wx.removeStorageSync('userId')
      }
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})